////////////////////////////////////////////////////////////////////////////////
//(c) Intelliquip, Inc. 2001
////////////////////////////////////////////////////////////////////////////////
//$Log:
// 3    Version 10.0 (Current View)1.2         6/1/2011 2:03:57 PM    Scott
//      Frees     IDD 09911:  xSheets and IQX integration
// 2    Version 10.0 (Current View)1.1         5/19/2011 2:24:00 PM   Jeff
//      Heigl      IDD#09827: refactoring to template method pattern
// 1    Version 10.0 (Current View)1.0         5/19/2011 11:06:37 AM  Jeff
//      Heigl      
//$
//$NoKeywords$
////////////////////////////////////////////////////////////////////////////////
package com.intelliquip.hydraulicselection.control.web;

import com.intelliquip.core.Applications;
import com.intelliquip.util.ServletUtils;
import com.intelliquip.util.StringUtils;
import com.intelliquip.util.UrlPathAppender;

public abstract class RedirectConfig extends RedirectApp{

	
	public RedirectConfig(RedirectParams parameterObject) {
		super(parameterObject);
	}

	
	private void validateConfigBaseDir() throws RedirectValidationException {
		String configBaseDir = userPreferences.getConfigBaseDir(productLineWeb);
		if(!StringUtils.isDefined(configBaseDir)) {
			String label = pageLabels.getLabel("configurationNotAvailable");
			throw new RedirectValidationException(label, getCurrentScreenUrl());
		}
	}

	@Override 
	protected void validateApp() throws RedirectValidationException {
		validateConfigBaseDir();
	}
	
	@Override
	protected String buildRedirectUrl(int itemTempId, String configTargetServlet) {
		String orgFolderHome = userPreferences.getOrgFolderHome();
		String configBaseDir = userPreferences.getConfigBaseDirForCurrentResult();
		String destination = Applications.getConfiguratorItemRetrieval();
		String configEntryURL = Applications.getConfiguratorNewEntryUrl( orgFolderHome, configBaseDir, destination);

		String url = new UrlPathAppender()
			.append(ServletUtils.getScheme_ServerName_Port(request))
			.append(configEntryURL)
			.build();

		url = ServletUtils.addParametersToURL(url, new String[][] {
				{"targetServlet", configTargetServlet},
				{"UID", userPreferences.getUser().getDynamicID()},
				{"itemIDTemp", String.valueOf(itemTempId)}
		});

		return url;
	}

}
